class SelSort
{
    private static void swap(Comparable[] arr, int x, int y)
    {
        Comparable tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
    }

    public static void sort(Comparable[] arr)
    {
        for (int i=0; i<arr.length-1; i++)
        {
            int small = i;
            for (int j=i+1; j<arr.length; j++)
            {
                if (arr[j].compareTo(arr[small]) < 0)
                    small = j;
            }
            swap(arr, small, i);
        }
    }

    public static void main(String[] arr)
    {
        Double[] nb = new Double[5];
        System.out.println("before");
        for (int i=0; i<nb.length; i++)
        {
            nb[i] = new Double(Math.random());
            System.out.println(i+") "+nb[i]);
        }
        sort(nb);
        System.out.println("after");
        for (int i=0; i<nb.length; i++)
            System.out.println(i+") "+nb[i]);
    }
}
